<?php
require_once 'BaseMySQLDAO.php';

class GameTagDAO extends BaseMySQLDAO {

    public function __construct($context) {
        parent::__construct($context, 'game_statistic');
    }

    public function getGameTagByTagId($tagId) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction();

            $inSQL = "SELECT * FROM game_tag WHERE id in (".$tagId.")";


            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getGameTagByID($id) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction();

            $inSQL = "SELECT * FROM game_tag WHERE id = :id";
            $param = array(":id" => $id);
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadOneRow($inSQL, $param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getFullGameTag() {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction();

            $inSQL = "SELECT * FROM game_tag";

            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
    public function getFullGameTagTPG() {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');

            $inSQL = "SELECT * FROM game_tag ORDER BY id DESC";

            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
 	public function getFullGameTagMobile() {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('mobile');

            $inSQL = "SELECT * FROM game_tag ORDER BY id DESC";

            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getFullGameTagCGMB() {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('choigamemobi');

            $inSQL = "SELECT * FROM game_tag ORDER BY id DESC";

            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getFullGameTagMMBG() {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('mymobigame');

            $inSQL = "SELECT * FROM game_tag ORDER BY id DESC";

            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getFullGameTagNSGT() {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('ngoisaogamethu');

            $inSQL = "SELECT * FROM game_tag ORDER BY id DESC";

            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function getFullGameTagByName($name) {
        $result = array();
        try {
            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');

            $inSQL = "SELECT * FROM game_tag WHERE id= :name ORDER BY id DESC";
			$param = array(":name" => $name);
            $result = $this -> getContext() -> getTransaction() -> getMySQLConnection() -> loadManyRow($inSQL,$param);

            $this -> getContext() -> getTransaction() -> closeTransaction();
        } catch (Exception $exception) {
            $this -> getContext() -> logException($exception);
        }
        return $result;
    }
    
	public function insertGameTag($param) {
        $result = null;
        try {
            $inSQL = "INSERT INTO
                        game_tag(id, name, title, link)
                        VALUES (
                            :id, :name, :title, :link
                        )";
            $queryParam = array(
                                ':id' => NULL,
                                ':name' => $param['name'],
                                ':title' => $param['title'],
                                ':link' => $param['link'],
                            );
            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();
            
            $this -> getContext() -> getTransaction() -> startTransaction('mobile');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

            $this -> getContext() -> getTransaction() -> startTransaction('choigamemobi');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

            $this -> getContext() -> getTransaction() -> startTransaction('mymobigame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();
            
            $this -> getContext() -> getTransaction() -> startTransaction('ngoisaogamethu');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

        } catch (Exception $exception) {
            print_r($exception);
            exit;
        }
        return $result;
    }
    
	public function updateGameTag($param) {
        $result = null;
        try {
            $inSQL = "UPDATE game_tag SET
                                    name = :name,
                                    title = :title,
                                    link = :link
                        WHERE id = :id 
                       ";
            $queryParam = array(
                                ':id' => $param['id'],
                                ':name' => $param['name'],
                                ':title' => $param['title'],
                                ':link' => $param['link'],
                            );
            $this -> getContext() -> getTransaction() -> startTransaction('thanhphogame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();
            
            $this -> getContext() -> getTransaction() -> startTransaction('mobile');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

            $this -> getContext() -> getTransaction() -> startTransaction('choigamemobi');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

            $this -> getContext() -> getTransaction() -> startTransaction('mymobigame');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();
            
            $this -> getContext() -> getTransaction() -> startTransaction('ngoisaogamethu');
            $this -> getContext() -> getTransaction() -> getMySQLConnection() -> executeNonQuery($inSQL, $queryParam);
            $this -> getContext() -> getTransaction() -> closeTransaction();

        } catch (Exception $exception) {
            print_r($exception);
            exit;
        }
        return $result;
    }

}
?>